package com.abc.robot01.activity

import android.os.Bundle
import android.util.Log
import android.webkit.WebSettings
import android.webkit.WebView
import android.webkit.WebViewClient
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.rememberScrollState
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.Text
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.ComposeView
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.unit.dp
import com.abc.robot01.R

/**
 * 方案720页面 加 户型选择
 */
class FangAnActivity : BaseVoiceActivity() {

    private lateinit var webView: WebView
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val designPackageId = intent.getStringExtra("designPackageId");
        this.setContentView(R.layout.content_main5)
        webView = findViewById<WebView>(R.id.webView)
        webView.settings.javaScriptEnabled = true
        webView.settings.cacheMode = WebSettings.LOAD_DEFAULT
        webView.settings.domStorageEnabled = true
        // Ensure the WebView opens URLs in the WebView itself
        webView.webViewClient = WebViewClient()
        val renderUrl = intent.getStringExtra("renderUrl")
        val id = intent.getStringExtra("id")
        Log.e(TAG, "renderUrl:$renderUrl")
        webView.loadUrl(renderUrl!!)

        val c = findViewById<ComposeView>(R.id.compose_view)
        c.setContent {
            val scrollState = rememberScrollState()
            MaterialTheme {
                Box {
//                    Image(painter = painterResource(id = R.drawable.z1), contentDescription = "")
                    Row(modifier = Modifier.padding(30.px)) {
                        BackButton {
                        }
                    }

                    OutlinedButton(
                        onClick = {
                            startActivity<HuXingXuanZheActivity>() {
                                putExtra("designPackageId", designPackageId)
                            }
                        },
                        border = BorderStroke(width = 1.dp, color = Color.White.copy(alpha = 0.5f)),
                        contentPadding = PaddingValues(0.dp),
                        modifier = Modifier
                            .padding(0.dp)
                            .offset(x = 482.dp, y = 224.dp)
                            .size((52 * 3.5f).toInt().px, (28 * 3.5f).toInt().px),
                    ) {
                        Text(
                            text = "户型选择",
                            style = TextStyle(color = Color.White), fontSize = 30.mysp
                        )
                    }


                }
            }
        }
        Log.e(TAG, "onCreate");
    }

    override fun onDestroy() {
        super.onDestroy()
        Log.e(TAG, "onDestroy")
        webView.destroy()
    }

    companion object {
        val TAG = "FangAnActivity"
    }

}
